package com.fjwt.gz.mch.ctrl.equity;

import com.alibaba.fastjson.JSON;
import com.fjwt.gz.core.model.ApiRes;
import com.fjwt.gz.db.vo.AgentEquityVO;
import com.fjwt.gz.mch.ctrl.CommonCtrl;
import com.fjwt.gz.service.impl.AgentEquityService;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.weaver.loadtime.Agent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/api/equity")
public class EquityMultiplierController extends CommonCtrl{

    @Autowired
    private AgentEquityService equityMultiplierService;

    /**
     * 根据权益ID查询下级权益（二级查三级）
     */
    @PostMapping("/selectLevelEquity")
    public ApiRes selectLevelEquity() {
        Integer pid = getValInteger("scoreExchangeId");
        String locationAgentNo = request.getHeader("locationAgentNo");
        log.info("C端根据权益Id查询权益，请求地址：/api/equity/selectLevelEquity，请求参数：agentEquityId：{}，agentNo：{}",pid,locationAgentNo);
        List<AgentEquityVO> list = equityMultiplierService.selectLevelEquity(pid,locationAgentNo);
        log.info("C端根据权益Id查询权益，请求地址：/api/equity/selectLevelEquity，返回结果：{}", JSON.toJSONString(list));
        List<AgentEquityVO> vos = List.copyOf(list);
        return ApiRes.ok(vos);
    }

    /**
     * 根据资产等级查询权益（一级查二级）
     */
    @PostMapping("/selectAssetLevelEquity")
    public ApiRes selectAssetLevelEquity() {
        Integer level = getValInteger("level");
        String locationAgentNo = request.getHeader("locationAgentNo");
        log.info("C端根据资产等级查询权益查询，请求地址：/api/equity/selectAssetLevelEquity，请求参数：level：{}，agentNo：{}",level,locationAgentNo);
        List<AgentEquityVO> list = equityMultiplierService.selectParentLevelEquity(level,locationAgentNo);
        log.info("C端根据资产等级查询权益查询，请求地址：/api/equity/selectAssetLevelEquity，返回结果：{}", JSON.toJSONString(list));
        List<AgentEquityVO> vos = List.copyOf(list);
        return ApiRes.ok(vos);
    }

    /**
     * 查询权益栏目名称
     */
    @PostMapping("/selectEquityName")
    public ApiRes selectEquityName() {
        Long pid = getValLong("pid");
        String locationAgentNo = request.getHeader("locationAgentNo");
        log.info("C端查询权益栏目名称，请求地址：/api/equity/selectEquityName，权益agentEquityPId：{}, agentNo:{}", pid, locationAgentNo);
        List<AgentEquityVO> list = equityMultiplierService.selectEquityName(pid, locationAgentNo);
        log.info("C端查询权益栏目名称，请求地址：/api/equity/selectEquityName，返回结果：{}", JSON.toJSONString(list));
        return ApiRes.ok(list);
    }

}
